local yishi = fk.CreateSkill {
  name = "lvshi__yishi",
  anim_type = "control",
}

Fk:loadTranslationTable{
  ["lvshi__yishi"] = "弈势",
  [":lvshi__yishi"] = "每局各限一次，技能数大于/等于/小于你的角色受到伤害时，你可以令此伤害+1或-1。",
}

-- 伤害事件处理
yishi:addEffect(fk.DamageInflicted, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(yishi.name) or #player:getTableMark("yishi_used") >= 3 then return end
    -- 计算技能数量（剔除装备技能和其他角色的技能）
    local player_skill_count = #player:getSkillNameList()
    local target_skill_count = #target:getSkillNameList()
    -- 判断技能数量关系
    local skill_relation
    if target_skill_count > player_skill_count then
      skill_relation = "greater"
    elseif target_skill_count == player_skill_count then
      skill_relation = "equal"
    else
      skill_relation = "less"
    end
    -- 检查对应的使用状态
    return not table.contains(player:getTableMark("yishi_used"), skill_relation)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skill_relation
    local player_skill_count = #player:getSkillNameList()
    local target_skill_count = #target:getSkillNameList()
    if target_skill_count > player_skill_count then
      skill_relation = "greater"
    elseif target_skill_count == player_skill_count then
      skill_relation = "equal"
    else
      skill_relation = "less"
    end
    local record = player:getTableMark("yishi_used")
    table.insertIfNeed(record, skill_relation)
    room:setPlayerMark(player, "yishi_used", record)
    local choices = {"damage_plus", "damage_minus"}
    local choice = room:askToChoice(player, {choices = choices, skill_name = yishi.name, 
      prompt = "#lvshi__yishi-choice::"..target.id..":"..data.damage})
    
    -- 调整伤害
    if choice == "damage_plus" then
      data:changeDamage(1)
      room:sendLog{
        type = "$YishiDamageChange",
        from = player.id,
        to = {target.id},
        arg = data.damage,
        toast = true,
      }
    elseif choice == "damage_minus" then
      data:changeDamage(-1)
      room:sendLog{
        type = "$YishiDamageChange",
        from = player.id,
        to = {target.id},
        arg = data.damage,
        toast = true,
      }
    end
  end,
})

-- 添加翻译文本
Fk:loadTranslationTable{
  ["#lvshi__yishi-choice"] = "弈势：你可以令 %dest 受到的 %arg 点伤害+1或-1",
  ["damage_plus"] = "+1",
  ["damage_minus"] = "-1",
  ["$YishiDamageChange"] = "%from 使用技能【弈势】令 %to 受到的伤害变为 %arg 点",
  ["greater"] = "大于",
  ["equal"] = "等于", 
  ["less"] = "小于",
}

return yishi